package com.rocketmq.base.example.batch;

import com.rocketmq.base.example.Const;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: tianchao
 * @Date: 2021/9/2 17:11
 * @Description:
 */
public class BatchProducer {
    public static void main(String[] args) throws Exception {
        String topic = "BatchTest";
        DefaultMQProducer defaultMQProducer = new DefaultMQProducer("my_order_producer_group_name");
        defaultMQProducer.setNamesrvAddr(Const.nameServer);
        defaultMQProducer.start();
        List<Message> messages = new ArrayList<>();
        messages.add(new Message(topic, "TagA", "OrderID001", "Hello world 0".getBytes()));
        messages.add(new Message(topic, "TagA", "OrderID002", "Hello world 1".getBytes()));
        messages.add(new Message(topic, "TagA", "OrderID003", "Hello world 2".getBytes()));
        try {
            defaultMQProducer.send(messages);
        } catch (Exception e) {
            e.printStackTrace();
            //handle the error
        }
    }
}
